package com.example.a14110100420.yuejian.Fragment.club;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.a14110100420.yuejian.R;
import com.example.a14110100420.yuejian.WAdapter.club.ClubCoureAdapter;
import com.example.a14110100420.yuejian.WSerivice.ClubService;
import com.example.a14110100420.yuejian.Wbase.Conast;
import com.example.a14110100420.yuejian.Wbean.club.ClubCourse;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * A simple {@link Fragment} subclass.
 */
public class Club_Course_Fragment extends Fragment {
    private View view;
    private String map;
    private String clubid;
    private RecyclerView recyclerView;


    public Club_Course_Fragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view =  inflater.inflate(R.layout.activity_club__course_, container, false);
        recyclerView = view.findViewById(R.id.course_rv);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        init();
        return view;
    }
    private void init(){
        Intent intent = getActivity().getIntent();
        clubid = intent.getStringExtra("clubid");
        map="Clubcourse";
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Conast.base_Url)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        ClubService service = retrofit.create(ClubService.class);
        Call<ClubCourse> call = service.getClubCourse(clubid,map);
        call.enqueue(new Callback<ClubCourse>() {
            @Override
            public void onResponse(Call<ClubCourse> call, Response<ClubCourse> response) {
                List<ClubCourse.ClubcourseEntity> clubCourse = response.body().getClubcourse();
                if (null != clubCourse) {
                    ClubCoureAdapter adapter = new ClubCoureAdapter(getActivity(),clubCourse);
                    recyclerView.setAdapter(adapter);
                }
            }

            @Override
            public void onFailure(Call<ClubCourse> call, Throwable t) {

            }
        });

    }

}
